home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Aminet 5
/
Aminet 5 - March 1995.iso
/
Aminet
/
util
/
wb
/
cachecontrol.lha
/
cc.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-06-19
|
5KB
|
212 lines
/* CC.c */
/* Cachebits zeile 189 ff */
#include "sc:source/cc/cc-INCLUDES.h"
/* Version | Revisionscontrol */
#define VERSION 1
#define REVISION 10
#define DATE "__Date__"
#define VERS "CacheControl 1.10"
#define VSTRING "CacheControl 1.10 ("__DATE__")\n\r"
#define VERSTAG "\0$VER: CacheControl 1.10 ("__DATE__")"
void OpenAll(void);
void CloseAll(void);
/* Externs */
extern struct ExecBase *SysBase;
/* Globals */
UBYTE VersTag[]=VERSTAG; /* Versionsstring */
struct IntuitionBase *IntuitionBase=0l;
struct GfxBase *GfxBase=0l;
struct Library *UtilityBase=0l,*DiskfontBase=0l;
struct Screen *scr=0l;
struct Window *win=0l;
struct Gadget *GList=0l;
struct TextAttr *sysfont=0l;
ULONG oldbits,cachebits,cachemask;
UBYTE icache,iburst,dcache,dburst,copyback;
struct TagItem wintags[]={
WA_Left, 50,
WA_Top, 20,
WA_InnerWidth, 200,
WA_InnerHeight, 70,
WA_IDCMP, IDCMP_CLOSEWINDOW|IDCMP_VANILLAKEY|BUTTONIDCMP,
WA_Flags, WFLG_SMART_REFRESH|WFLG_ACTIVATE|WFLG_CLOSEGADGET|WFLG_DRAGBAR|WFLG_DEPTHGADGET|WFLG_GIMMEZEROZERO|WFLG_RMBTRAP,
WA_Title, (ULONG *)"CacheControl V1.10",
WA_ScreenTitle, (ULONG *)"CacheControl V1.10 (C) 1994 by ENSONIC of TRINOMIC",
WA_CustomScreen, 0l,
WA_Gadgets, 0l,
WA_PubScreenName, 0l,
WA_PubScreenFallBack, TRUE,
TAG_DONE
};
UBYTE *DCLabels[]={"DCache Off","DCache On",0l };
UBYTE *DBLabels[]={"DBurst Off","DBurst On",0l };
UBYTE *ICLabels[]={"ICache Off","ICache On",0l };
UBYTE *IBLabels[]={"IBurst Off","IBurst On",0l };
UBYTE *CBLabels[]={"CopyBack Off","CopyBack On",0l };
void OpenAll(void)
{
WORD winx,winy,fonty,gwidth;
struct NewGadget ng;
struct Gadget *g;
APTR VisualInfo=0l;
struct RastPort *rp;
UWORD level,syslevel;
syslevel=0;
level=SysBase->AttnFlags;
if(level&(1<<1)) syslevel=1;
if(level&(1<<2)) syslevel=2;
if(level&(1<<3)) syslevel=3;
if(!syslevel) exit(1);
oldbits=CacheControl(0l,0l);
dcache=dburst=icache=iburst=copyback=0;
if(oldbits&(1L<< 8)) dcache=1;
if(oldbits&(1L<<12)) dburst=1;
if(oldbits&(1L<< 0)) icache=1;
if(oldbits&(1L<< 4)) iburst=1;
if(oldbits&(1L<<31)) copyback=1;
if(!(IntuitionBase=OpenLibrary("intuition.library",37))) CloseAll();
if(!(GfxBase=OpenLibrary("graphics.library",37))) CloseAll();
if(!(UtilityBase=OpenLibrary("utility.library",37))) CloseAll();
if(!(scr=LockPubScreen(0l))) CloseAll();
sysfont=scr->Font;
rp=&scr->RastPort;
fonty=max(11,(sysfont->ta_YSize+4));
winy=(syslevel*fonty)+5;
gwidth=TextLength(rp,CBLabels[0],strlen(CBLabels[0]))+30;
winx=gwidth+gwidth+10;
if(!(VisualInfo=GetVisualInfo(scr,TAG_DONE))) CloseAll();
if(!(g=CreateContext(&GList))) CloseAll();
if(syslevel>0)
{
ng.ng_LeftEdge =4;
ng.ng_TopEdge =2;
ng.ng_Width =gwidth;
ng.ng_Height =fonty;
ng.ng_GadgetText ="";
ng.ng_TextAttr =sysfont;
ng.ng_GadgetID =0;
ng.ng_Flags =PLACETEXT_LEFT;
ng.ng_VisualInfo =VisualInfo;
g=CreateGadget(CYCLE_KIND,g,&ng,GTCY_Labels,&DCLabels,GTCY_Active,dcache,TAG_DONE);
ng.ng_LeftEdge =gwidth+6;
ng.ng_GadgetID =1;
g=CreateGadget(CYCLE_KIND,g,&ng,GTCY_Labels,&DBLabels,GTCY_Active,dburst,TAG_DONE);
}
if(syslevel>1)
{
ng.ng_LeftEdge =4;
ng.ng_TopEdge =2+(fonty+1);
ng.ng_GadgetID =2;
g=CreateGadget(CYCLE_KIND,g,&ng,GTCY_Labels,&ICLabels,GTCY_Active,icache,TAG_DONE);
ng.ng_LeftEdge =gwidth+6;
ng.ng_GadgetID =3;
g=CreateGadget(CYCLE_KIND,g,&ng,GTCY_Labels,&IBLabels,GTCY_Active,iburst,TAG_DONE);
}
if(syslevel>2)
{
ng.ng_LeftEdge =4;
ng.ng_TopEdge =2+(fonty+1)+(fonty+1);
ng.ng_GadgetID =4;
g=CreateGadget(CYCLE_KIND,g,&ng,GTCY_Labels,&CBLabels,GTCY_Active,copyback,TAG_DONE);
}
wintags[2].ti_Data=winx;
wintags[3].ti_Data=winy;
wintags[8].ti_Data=scr;
wintags[9].ti_Data=GList;
if(!(win=OpenWindowTagList(0l,wintags))) CloseAll();
UnlockPubScreen(0l,scr);
}
void CloseAll(void)
{
if(win) CloseWindow(win);
if(UtilityBase) CloseLibrary(UtilityBase);
if(GfxBase) CloseLibrary(GfxBase);
if(IntuitionBase) CloseLibrary(IntuitionBase);
exit(1);
}
void main()
{
struct IntuiMessage *imsg;
ULONG iclass;
APTR iadr;
USHORT icode;
UBYTE quit=0;
OpenAll();
while(!quit)
{
WaitPort(win->UserPort);
while(imsg=GT_GetIMsg(win->UserPort))
{
iclass =imsg->Class;
iadr =imsg->IAddress;
icode =imsg->Code;
GT_ReplyIMsg(imsg);
switch(iclass)
{
case IDCMP_GADGETUP:
switch((int)(((struct Gadget *)iadr)->GadgetID))
{
case 0: /* DCache On/Off */
if(icode) cachebits=cachemask=(1L<<8);
else { cachebits=0;cachemask=(1L<<8); }
CacheControl(cachebits,cachemask);
break;
case 1: /* DBurst On/Off */
if(icode) cachebits=cachemask=(1L<<12);
else { cachebits=0;cachemask=(1L<<12); }
CacheControl(cachebits,cachemask);
break;
case 2: /* ICache On/Off */
if(icode) cachebits=cachemask=1L;
else { cachebits=0;cachemask=1L; }
CacheControl(cachebits,cachemask);
break;
case 3: /* IBurst On/Off */
if(icode) cachebits=cachemask=(1L<<4);
else { cachebits=0;cachemask=(1L<<4); }
CacheControl(cachebits,cachemask);
break;
case 4: /* CopyBack On/Off */
if(icode) cachebits=cachemask=(1L<<31);
else { cachebits=0;cachemask=(1L<<31); }
CacheControl(cachebits,cachemask);
break;
}
break;
case IDCMP_CLOSEWINDOW:
quit=1;break;
}
}
}
CloseAll();
}